import request from '/utils/request'

export const knowledgeApi = {
  /** 获取知识分类列表 */
  getKnowledge(params: KnowledgeOptions) {
    return request.get('/knowledge', { params })
  },
  /** 获取知识分类 */
  getKnowledgeClassify(): Promise<DomoFeedCategory[]> {
    return request.get(`/knowledge/categories`)
  },
  /** 获取单个知识 */
  getKnowledgeDetail(id: number): Promise<GetKnowledgeReturn> {
    return request.get(`/knowledge/${id}`)
  },
  /** 获取章节列表 */
  getKnowledgChapters(params: GetKnowledgeChaptersParams) {
    return request.get(`/knowledge/chapters`, { params })
  },
  /** 获取单个知识的点评 */
  getKnowledgeComment(knowledgeId: number, params?: GetKnowledgeCommentParams) {
    return request.get(`/knowledge/${knowledgeId}/comments`, { params })
  },
  /** 取消收藏知识 */
  unCollectKnowledge(knowledgeId: number) {
    return request.delete(`/knowledge/${knowledgeId}/like`)
  },
  /** 收藏知识 */
  collectKnowledge(knowledgeId: number) {
    return request.put(`/knowledge/${knowledgeId}/like`)
  },
  /** 举报知识 */
  reportKnowledge(knowledgeId: number, payload: ReportKnowledgePramas) {
    return request.post(`/knowledge/${knowledgeId}/reports`, payload)
  },
  /** 获取单个章节 */
  getKnowledgChapter(chapterId: number) {
    return request.get(`/knowledge/chapters/${chapterId}?with[]=prev&with[]=next`)
  },
  /** 创建知识订单 */
  postKnowledgeOrder(payload: any) {
    payload.pay_method = 'WechatPay_Js'
    return request.post(`/knowledge/orders`, payload)
  },
  /** 获取知识订单列表 */
  getKonwledgeOrder(params: GetOrderListParmas) {
    return request.get('/knowledge/orders', { params })
  },
  /** 获取知识订单列表,单个订单id */
  getKonwledgeOrderById(params: GetOrderListParmas) {
    return request.get('/knowledge/orders', { params })
  },
  /** 修改单个订单 */
  resetKnowledgeOrder(orderId: number, params: DeletOrderPramas) {
    return request.patch(`/knowledge/orders/${orderId}`, params)
  },
  /** 检测用户是否可以发布知识 */
  canPublishKnowledge(params: any): Promise<CanPublish> {
    return request.get('/knowledge/can-publish', params)
  },
  /** 发布知识 */
  creatKnowledge(payload: any) {
    return request.post('/knowledge', payload)
  },
  /** 添加知识章节 */
  addChapter(payload: any) {
    return request.post(`/knowledge/chapters`, payload)
  },
  /** 编辑知识章节 */
  editorChapter(id: number, payload: any) {
    return request.patch(`/knowledge/chapters/${id}`, payload)
  },
  /** 编辑知识 */
  editorKnowledge(id: number, payload: any) {
    return request.patch(`/knowledge/${id}`, payload)
  },
  /** 删除知识章节 */
  deleteChapters(id: number) {
    return request.delete(`/knowledge/chapters/${id}`)
  },
  /** 删除知识 */
  deleteKnowledge(id: number) {
    return request.delete(`/knowledge/${id}`)
  },
}
